package com.servertest1;

import android.content.Context;
import android.graphics.Color;
import android.graphics.PorterDuff.Mode;
import android.util.AttributeSet;
import android.widget.Button;
import android.widget.ImageView;


public class Square extends ImageView{
	//Possible spaces
	private static final int BOMB_SPACE = 'B';
	private static final int FLAGGED_SPACE = 'F';
	
	private boolean isCovered;
	private int value;
	private boolean isFlagged;

	public Square(Context context) {
		super(context);
		this.isCovered = true;
		this.value = 0;
		this.isFlagged = false;
	}

	public Square(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.isCovered = true;
		this.value = 0;
		this.isFlagged = false;
	}

	public Square(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		this.isCovered = true;
		this.value = 0;
		this.isFlagged = false;
	}

	public void setValue(int value){
		this.value = value;
	}
	
	public void updateFlag(){
		this.isFlagged = !this.isFlagged;
	}

	public void showText(){		
		// Set the text to be displayed on the square
		
		if(this.isCovered && (!this.isFlagged)){
			this.setImageResource(R.drawable.square_covered);
			return;
		}
		else if (this.isCovered && (this.isFlagged)){
			this.setImageResource(R.drawable.square_flagged);
		}
		else if (value <= 8 && value > 0){
			if(value == 1)
				this.setImageResource(R.drawable.square1);
			if(value == 2)
				this.setImageResource(R.drawable.square2);
			if(value == 3)
				this.setImageResource(R.drawable.square3);
			if(value==4)
				this.setImageResource(R.drawable.square4);
			if(value==5)
				this.setImageResource(R.drawable.square5);
		}
		else if (value == BOMB_SPACE)
			this.setImageResource(R.drawable.mine_logo);		
		else
			this.setImageResource(R.drawable.blank_square);

	}

	public int getValue(){
		return this.value;
	}

	public void setCover(boolean covered){
		this.isCovered = covered;
		
		if(!covered){
			this.isFlagged = false;
		}
	}

	public boolean isCovered(){
		return this.isCovered;
	}
	
	public boolean isFlagged(){
		return this.isFlagged;
	}
}